<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2022/3/16
 */

namespace App\Http\Controllers;

use App\Models\InfoCategory;
use App\Services\AdsService;
use App\Services\InfoCategoryService;
use App\Services\MetaService;

/**
 * 单页模块
 * Class InfoPictureController
 * @package App\Http\Controllers
 */
class InfoPageController extends Controller
{
    /**
     * 单页栏目首页
     * @return mixed
     */
    function index(InfoCategory $cate)
    {
        if ($cate->type != 3) abort(404);

        // 模板、数据
        $template = 'info-page/' . ($cate->index_template ?: 'index');
        $data = [];
        $data['meta'] = MetaService::cateMeta($cate);
        $data['category'] = $cate;
        $data['subCategory'] = InfoCategoryService::getAllSubsTreeByParentId($cate['id']);
        $data['breadcrumb'] = InfoCategoryService::getBreadcrumb($cate);
        $data['ads'] = AdsService::getAdsByInfoCategoryId($cate->id); // 栏目关联广告
        return $this->view($template ,$data);
    }
}
